<?php $this->load->view(TEMPLATE_NAME.'/admin/header');?>
<?php $this->load->view(TEMPLATE_NAME.'/admin/side_left');?>
<script type="text/javascript" src="<?php echo base_url()?>js/jquery-1.4.2.js"></script> 
<script type="text/javascript" src="<?php echo base_url()?>js/jquery.validate.pack.js"></script>
<script src="<?php echo base_url(); ?>js/ajaxfileupload.js"></script>
<script src="<?php echo base_url(); ?>js/si.files.js"></script>
<style type="text/css" title="text/css">
.SI-FILES-STYLIZED label.cabinet
{
    width: 100px;
    height: 28px;
    background: url(<?php echo base_url()?>image/select_image.jpg) 0 0 no-repeat;
    display: block;
    overflow: hidden;
    cursor: pointer;
}

.SI-FILES-STYLIZED label.cabinet input.file
{
    position: relative;
    height: 100%;
    width: auto;
    opacity: 0;
    -moz-opacity: 0;
    filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);
}
.profile_image {
    float:left;
    display:inline;
    position:relative;
}
</style>
<script type="text/javascript">
SI.Files.stylizeAll();       
    $(document).ready(function(){
        /* jquery validation */
        //custom validation rule - username not equal with 'Your e-mail address
        $('#pass').hide();    
        $("#login_details").validate({
            rules: {
                username: "required",
                firstname: "required",
                surname: "required",
                email: "required",
                
                password : {                   
                    minlength: 6    
                },
                passconf : {                         
                    minlength: 6,   
					equalTo: "#password"
                }                
               
            },
            messages: {
                username: "Please enter your Username",
                firstname : "Please enter your Password",
                surname: "Please enter your Surname",
                email: "Please enter your E-mail",  
				password: { 
					minlength: "Your password must be at least 6 characters long"
				},
				passconf: { 
					minlength: "Your password must be at least 6 characters long",
					equalTo: "Please enter the same password as above"
				}                 
			}
			 
        });
	    $('#clear').click(function(){
            $("#info").html('<img src="<?php echo base_url()?>xhtml/img/badut.gif" height="52" width="52" />'
            +'<input type="hidden" name="upload" value="">');            
            return false;       
        }); 
        
        /* end jquery validation */
    });
// function upload jquery
function ajaxFileUpload(){
    $("#loading")
    .ajaxStart(function(){
        $(this).show();
    })
    .ajaxComplete(function(){
        $(this).hide();
    });

    $.ajaxFileUpload({
        //url:'<?php //echo site_url('admin/profile/do_upload')?>',
        url:'<?php echo site_url('ajax_upload/upload_directory_image/upload/profile')?>',
        secureuri:false,
        fileElementId:'fileToUpload',
        dataType: 'json',
        success: function (data, status){      
            if(typeof(data.error) != 'undefined'){
                if(data.error != ''){
                    $("#info").html(data.error);
                }else{
                    //$("#info").html(data.msg);
                    $("#info").html('<img src="<?php echo base_url();?>uploads/profile/crop/'+data.msg+'" /><br />'
                    +'<input type="hidden" name="upload" value="'+data.msg +'">');
                }
            }
        },
        error: function (data, status, e){
            $("#info").html(e);
        }
    })        
    return false;
}

</script>
<div class="page noright adminpage adminuser">
    
    <?php $this->load->view(TEMPLATE_NAME.'/admin/profile/profile_tabs');?>
    <h2 class="no">Login Details</h2>
		<?php if(!empty($notification)): ?>
		<p><?php echo $notification ?></p><div style="clear:both"></div>
		<?php endif; ?>

        <!--<form class="formstep" action="#">-->
             
        <?php 
  
        if ($error){
            echo "<h2>Error!!!</h2><br />";
            if($error == '1'){
                echo validation_errors();
            }else{
                echo $error."<br />";    
            }
        }        
   
        ?>
        
        <?php 
        if ($upload_data){
            echo "<h2>Success!!!</h2><br />";            
        }?>         
        <?php echo form_open_multipart('admin/profile',array('method' => 'post', 'class' => 'formstep', 'id' => 'login_details'));?><br />
            <label>Username: <strong class="purple">*</strong></label>
            <?php echo form_input('username',$user_tiab['username']); ?><br />
	        <?php echo form_error('username','<p id="" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
            
            <label>Your Firstname: <strong class="purple">*</strong></label>
            <?php echo form_input('firstname',$user_tiab['firstname']); ?><br />
	        <?php echo form_error('firstname','<p id="" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
            <label>Your Surname: <strong class="purple">*</strong></label>
            <?php echo form_input('surname',$user_tiab['surname']); ?><br />
	        <?php echo form_error('surname','<p id="" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
            
            <label>E-mail: <strong class="purple">*</strong></label>
            <?php echo form_input('email',$user_tiab['email']); ?><br />
	        <?php echo form_error('email','<p id="" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
            
            <label>Password: <strong class="purple">*</strong></label>
            <strong class="f16"><?php echo mask_password($user_tiab['real_pass'],'*',3)?></strong><br /><br />
            
            <h2>Change Password</h2><br />
            <label>Password: <strong class="purple">*</strong></label>
            <?php echo form_password(array('name'=>'password','id' => 'password')); ?><br />
	        <?php echo form_error('password','<p id="" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
            
            <label>Confirm Password: <strong class="purple">*</strong></label>
            <?php echo form_password(array('name' => 'passconf','id' => 'passconf')); ?><br />
	        <?php echo form_error('passconf','<p id="" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
            <label id="pass" class="error"></label>
            <h2>Your Profile Pic or Avatar (optional)</h2><br />
            <div>
                <div class="profile_image" style="width:155px;">
                    <label>Current Image: <strong class="purple">*</strong></label>
                    &nbsp;<a id="clear" href="">clear current logo</a>
                </div>
                <div class="profile_image" style="width:70px;">
                    <img id="loading" src="<?php echo base_url()?>image/loading_blue.gif" style="display:none;position:absolute;z-index:1000;left:10px;top:10px">
                    <div id="info">            
                    <?php if((!empty($user_tiab['avatar'])) && (file_exists("./uploads/profile/crop/".$user_tiab['avatar']))){ 
                        echo img(array('src' => base_url().'uploads/profile/crop/'.$user_tiab['avatar'], 'class' => 'pic'));?>
                        <input type="hidden" name="upload" value="<?php echo $user_tiab['avatar'];?>">
                    <?php }else{?> 
                        <img height="52" width="52" src="<?php echo base_url(); ?>xhtml/img/badut.gif" />
                    <?php }?>
                    </div>
                </div>            
                <div class="profile_image" style="width:360px;">
				<!-- ie show button -->
				<?php if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)):?>
				      <input type="file" class="file" id="fileToUpload" name="fileToUpload" onchange="return ajaxFileUpload();" />
                 <?php else:  ?>
                    <label class="cabinet"> 
                        <input type="file" class="file" id="fileToUpload" name="fileToUpload" onchange="return ajaxFileUpload();" />
                    </label>
				<?php endif;?>
					<div class="clear"></div>
                    <span style="color:#666666;font-size:11px;">Select a JPG or GIF image</span>
                </div>
                <div class="clear"></div>
            </div>            
            <hr />
            <?php 
            $form_button = array(
              'type'=>'submit',
              'name'=>'submit',
              'value'=>'submit',
              'content'=>'Submit',
            );
            echo form_button($form_button) ?>
        <div class="clear"></div>
        </form><!-- formstep -->    
</div><!-- page -->
<?php $this->load->view(TEMPLATE_NAME.'/admin/footer');?>
